import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n('asset.position.fields');
const { t: common } = useI18n('common');
export const positionFields = {
  positionName: t('positionName'),
  positionType: t('positionType'),
  positionInfo: t('positionInfo'),
  imgUrl: t('imgUrl'),
};
//列表数据
export const columns: BasicColumn[] = [
  {
    title: positionFields.positionName,
    align: 'center',
    dataIndex: 'positionName',
  },
  {
    title: positionFields.positionInfo,
    align: 'center',
    dataIndex: 'positionInfo',
  },
  {
    title: positionFields.positionType,
    align: 'center',
    dataIndex: 'positionType',
    customRender: ({ text }) => {
      if (text) {
        return render.renderDict(text, 'positionType');
      }
      return '';
    },
  },
  {
    title: positionFields.imgUrl,
    align: 'center',
    dataIndex: 'imgUrl',
    customRender: ({ text }) => {
      if (text) {
        return render.renderImage({ text, size: 60 });
      }
      return '';
    },
  },
  // {
  //   title: common('createTime'),
  //   align: 'center',
  //   dataIndex: 'createdTime',
  // },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: positionFields.positionName,
    field: 'positionName',
    component: 'JInput',
    colProps: { span: 6 },
    componentProps: { type: 'like' },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: common('pid'),
    field: 'pid',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'asset_position,position_name,id',
      pidField: 'pid',
      pidValue: '0',
      condition: '{"position_type":"1"}',
      hasChildField: 'has_child',
      params: {
        a: 1,
      },
    },
  },
  {
    label: positionFields.positionName,
    field: 'positionName',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true }];
    },
  },
  {
    label: positionFields.positionInfo,
    field: 'positionInfo',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true }];
    },
  },
  {
    label: positionFields.positionType,
    field: 'positionType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'positionType',
      showChooseOption: false,
    },
    colProps: { span: 24 },
    ifShow({ model }) {
      console.log(model.pid, 'renderCallbackParams');
      return !+model.pid;
    },
    dynamicRules: () => {
      return [{ required: true }];
    },
  },
  {
    label: positionFields.imgUrl,
    field: 'imgUrl',
    component: 'JImageUpload',
  },

  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
